package com.fzshang.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzshang.commen.bean.Attribute;
import com.fzshang.commen.bean.AttributeClassification;
import com.fzshang.commen.bean.Commodity;
import com.fzshang.commen.bean.VarietyClassification;
import com.fzshang.commen.controller.BaseController;
import com.fzshang.commen.entity.ApiResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @AUTHOR 冯政尚
 * @DATE 2020/2/2 11:39
 * @DAY_NAME_FULL: 星期日
 */
@Controller
@RequestMapping(value = "publicClass")
public class PublicClassController extends BaseController {


    /**
     * @param attributeClassificationId
     * @return 根据属性分类id 查询属性名称
     */
    @RequestMapping(value = "selectByAttributeClassificationId")
    @ResponseBody
    public ApiResult selectByAttributeClassificationId(Long attributeClassificationId){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("attribute_classification_id",attributeClassificationId);
        return ApiResult.ok(attributeService.list(queryWrapper));
    }

    /**
     * @param id
     * @return 查询菜品分类名称
     */
    @RequestMapping(value = "selectVarietyClassification")
    @ResponseBody
    public VarietyClassification selectVarietyClassification(Long id){
        return varietyClassificationService.getById(id);
    }


    /**
     * @param id
     * @return 查询属性分类名称
     */
    @RequestMapping(value = "selectAttributeClassification")
    @ResponseBody
    public AttributeClassification selectAttributeClassification(Long id){
        return attributeClassificationService.getById(id);
    }

    /**
     * @param id
     * @return 查询属性名称
     */
    @RequestMapping(value = "selectAttribute")
    @ResponseBody
    public Attribute selectAttribute(Long id){
        return attributeService.getById(id);
    }

    /**
     * @param id
     * @return 根据id查询菜品
     */
    @RequestMapping(value = "selectById")
    @ResponseBody
    public ApiResult selectById(Long id){
        return ApiResult.ok(commodityService.getById(id));
    }
    /**
     * @param id
     * @return 根据id查询属性分类
     */
    @RequestMapping(value = "selectAttributeClassificationId")
    @ResponseBody
    public ApiResult selectAttributeClassificationId(Long id){
        Commodity commodity = commodityService.getById(id);
        //根据属性分类id 查询属性分类
        AttributeClassification attributeClassification = attributeClassificationService.getById(commodity.getAttributeClassificationId());
        //根据属性分类id查询属性
//        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq("attribute_classification_id",attributeClassification.getId());
//        List<Attribute> attributes = attributeService.list(queryWrapper);
        return ApiResult.ok(attributeClassification);
    }




}
